import 'package:architecture/os_size.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../base/base_chess_controller.dart';
import '../../widgets/text_button.dart';
import 'go_terms_controller.dart';
import 'package:tile/tile.dart';

class GoTermsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<GoTermsController>(
        init: GoTermsController(),
        builder: (controller) {
          return Scaffold(
            appBar: AppBar(title: Text('围棋术语')),
            body: Container(
              width: windowWidth * 0.98,
              margin: EdgeInsets.only(top: 15),
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Container(
                        width: windowWidth * 0.42,
                        margin: EdgeInsets.only(top: 15),
                        child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              _tileView(controller),
                              SizedBox(height: 10),
                              Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceEvenly,
                                children: [
                                  _button('悔棋', onPressed: () {
                                    controller.regret();
                                  }),
                                  _button('手顺', onPressed: () {
                                    controller.changeTileNum();
                                  }),
                                  _button('形势', onPressed: () {
                                    controller.situation();
                                  }),
                                  _button('数子', onPressed: () {
                                    controller.count();
                                  }),
                                  _button('推荐点', onPressed: () {}),
                                  _button('变化图', onPressed: () {})
                                ],
                              )
                            ])),
                    Expanded(
                        child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          controller.terms.value,
                          style: TextStyle(
                              fontSize: windowWidth * 0.02,
                              color: Colors.redAccent),
                        ),
                      ],
                    ))
                  ]),
            ),
          );
        });
  }

  _button(String text, {Function? onPressed}) {
    return Container(
        // margin: EdgeInsets.only(left: 10, right: 10),
        alignment: Alignment.centerLeft,
        child: MyTextButton(
            height: 25,
            text: text,
            confirm: () {
              onPressed?.call();
            },
            sideColor: Colors.deepPurpleAccent,
            backgroundColor: Colors.transparent,
            textStyle: TextStyle(color: Colors.deepPurpleAccent)));
  }

  _tileView(GoTermsController controller) {
    return Padding(
      padding: const EdgeInsets.only(left: 16.0, right: 0, top: 5, bottom: 6),
      child: TileView(
        controller.board,
        controller: controller.tileViewController,
        style: tileStyle,
      ),
    );
  }
}
